<template>
  <j-modal
    :title="title"
    :width="1500"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row :gutter="24">
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="月份">
              <!-- <a-input placeholder="请输入月份" v-decorator="['month', {}]" /> -->
              <a-date-picker style="width: 273px" showTime format='YYYY-MM' v-decorator="[ 'month', validatorRules.enterTime ]" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="业务编号">
              <a-input placeholder="请输入业务编号" v-decorator="['busNo', {}]" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="施工门店">
              <a-input placeholder="请输入施工门店" v-decorator="['shop', {}]" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="进店时间">
              <a-date-picker style="width: 273px" showTime format='YYYY-MM-DD HH:mm:ss' v-decorator="[ 'enterTime', validatorRules.enterTime ]" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="提车时间">
              <a-date-picker style="width: 273px" showTime format='YYYY-MM-DD HH:mm:ss' v-decorator="[ 'finishTime', {} ]" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="客户姓名">
              <a-input placeholder="请输入客户姓名" v-decorator="['name', {}]" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="手机号码">
              <a-input placeholder="请输入手机号码" v-decorator="['phone', {}]" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="车型">
              <a-input placeholder="请输入车型" v-decorator="['type', {}]" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="车牌号">
              <a-input placeholder="请输入车牌号" v-decorator="['carNumber', {}]" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="车架号">
              <a-input placeholder="请输入车架号" v-decorator="['carShelf', {}]" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="进店里程(km)">
              <a-input placeholder="请输入进店里程(km)" v-decorator="['mileage', {}]" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="颜色">
              <a-input placeholder="请输入颜色" v-decorator="['color', {}]" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="车况反馈">
              <a-input placeholder="请输入车况反馈" v-decorator="['feedback', {}]" />
            </a-form-item>
          </a-col>
          
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="所属大类">
              <a-input placeholder="请输入所属大类" v-decorator="['oneCategory', {}]" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="所属细类">
              <a-input placeholder="请输入所属细类" v-decorator="['twoCategory', {}]" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="产品编号/备注说明">
              <a-input placeholder="请输入产品编号/备注说明" v-decorator="['proRemark', {}]" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="应收小计">
              <a-input-number style="width: 273px" :min="0" :precision="2" placeholder="请输入应收小计" v-model="model.shouldPrice" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="施工数量">
              <a-input-number style="width: 273px" :min="0" placeholder="请输入施工数量" v-decorator="['num', {}]" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="实收小计">
              <a-input-number style="width: 273px" :min="0" :precision="2" placeholder="请输入实收小计" v-model="model.realPrice" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="未收小计">
              <a-input-number style="width: 273px" :min="0" :precision="2"  v-model="model.restPrice" disabled />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="业务员">
              <!-- <a-input placeholder="请输入业务员" v-decorator="['salesman', {}]" /> -->
              <j-dict-select-tag v-decorator="['salesman', {}]" placeholder="请选择业务员" :triggerChange="true"
               dictCode="sys_user,realname,id,sales=1 order by create_time"/>
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="客户来源">
              <a-input placeholder="请输入客户来源" v-decorator="['source', {}]" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="收款方式">
              <a-input placeholder="请输入收款方式" v-decorator="['payType', {}]" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="手续费">
              <a-input-number style="width: 273px" :min="0" :precision="2" placeholder="请输入手续费" v-model="model.proceduresPrice" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="材料成本">
              <a-input-number style="width: 273px" :min="0" :precision="2" placeholder="请输入材料成本" v-model="model.materialCost"  />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="销售核算/材料成本">
              <a-input-number style="width: 273px" :min="0" :precision="2" placeholder="请输入销售核算/材料成本" v-model="model.salesCost" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="运费">
              <a-input-number style="width: 273px" :min="0" :precision="2" placeholder="请输入运费" v-model="model.freight" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="外出/施工费用">
              <a-input-number style="width: 273px" :min="0" :precision="2" placeholder="请输入外出/施工费用" v-model="model.buildingCost" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="销售核算场地费">
              <a-input-number style="width: 273px" :min="0" :precision="2" placeholder="请输入销售核算场地费" v-model="model.siteCose" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="维修费用/其他外协费">
              <a-input-number style="width: 273px" :min="0" :precision="2" placeholder="请输入维修费用/其他外协费" v-model="model.maintainCose" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="销售返佣">
              <a-input-number style="width: 273px" :min="0" :precision="2" placeholder="请输入销售返佣" v-model="model.salesCommission" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="业务员提成">
              <a-input-number style="width: 273px" :min="0" :precision="2" placeholder="请输入业务员提成" v-model="model.commission" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="外援施工费用">
              <a-input-number style="width: 273px" :min="0" :precision="2" placeholder="请输入外援施工费用" v-model="model.foreignCose" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="外援团队组">
              <a-input placeholder="请输入外援团队组" v-decorator="['foreignGroup', {}]" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="销售核算施工费用">
              <a-input-number style="width: 273px" :min="0" :precision="2" placeholder="请输入销售核算施工费用" v-model="model.salesBuildPrice" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="施工提成总计">
              <a-input placeholder="请输入施工提成总计" v-model="model.buildingTotil" disabled />
            </a-form-item>
          </a-col>
          <a-col :xl="24" :lg="24" :md="24" :sm="24" style="border: 2px solid #5e5a5a6e;">
            <a-row :gutter="10" style="line-height:30px;">
              <a-col :span="5" class="col-right"><label class="item-label">施工明细</label></a-col>
              <a-col :span="10"><a-button type="text" @click="addItem()" style="line-height:17px;font-size:12px">新增施工明细</a-button></a-col>
            </a-row>
            <a-row v-for="(item,index) in detailList"  :key="'item_'+index" :gutter="10" style="line-height:35px;font-size:12px">
                <a-col :span="2" class="col-right"><label>人员</label></a-col>
                <a-col :span="5" class="col-left">
                   <!-- <pro-select type=2 :triggerChange=false v-model="item.proId" /> -->
                   <j-dict-select-tag v-model="item.name" placeholder="请选择施工师傅" :triggerChange="false" dictCode="buildPreson" />
                </a-col>
                <a-col :span="2" class="col-right"></a-col>
                <a-col :span="2" class="col-right"><label>价格</label></a-col>
                <a-col :span="5" class="col-left">
                  <a-input-number style="width: 273px" v-model="item.price" @change="itemPriceChanged"/>元
                </a-col>
                <a-col :span="3" >
                  <a-button type="text" @click="deleteItem(item,index)" style="font-size:12px;line-height:0px;">{{detailList.length==1?'清空明细':'删除明细'}}</a-button>
                </a-col>
            </a-row>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="毛利润/实收核算">
              <a-input placeholder="请输入毛利润/实收核算" v-model="model.grossProfit" disabled />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="毛利率/实收核算">
              <a-input placeholder="请输入毛利率/实收核算" v-model="model.grossRate" disabled />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="销售提成应收核算 ">
              <a-input placeholder="请输入销售提成应收核算 " v-model="model.salesCommissionPrice" disabled />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="销售提成利润占比">
              <a-input placeholder="请输入销售提成利润占比" v-model="model.proportionProfits" disabled />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="发票/质保">
              <a-input placeholder="请输入发票/质保" v-decorator="['bill', {}]" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="首次复检">
              <a-input placeholder="请输入首次复检" v-decorator="['oneCheck', {}]" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="二次复检">
              <a-input placeholder="请输入二次复检" v-decorator="['twoCheck', {}]" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="三次复检">
              <a-input placeholder="请输入三次复检" v-decorator="['threeCheck', {}]" />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="车况反馈图片(多张)">
              <j-image-upload text="上传" v-decorator="['feedbackImg', {}]" isMultiple ></j-image-upload>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"
  import JUpload from '@/components/jeecg/JUpload'
  import JImageUpload from '@/components/jeecg/JImageUpload'
  import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'

  export default {
    name: "SalesDetailModal",
    components: { JImageUpload,JUpload },
    data () {
      return {
        title:"操作",
        visible: false,
        detailList:[],
        model: {
          buildList:[],
          restPrice: 0,
          grossRate: 0,
          salesCommissionPrice: 0,
          proportionProfits: 0,
          buildingTotil: '',
          buildingCost: 0,
          commission: 0,
          foreignCose: 0,
          freight: 0,
          grossProfit: 0,
          maintainCose: 0,
          materialCost: 0,
          proceduresPrice: 0,
          realPrice: 0,
          salesBuildPrice: 0,
          salesCommission: 0,
          salesCost: 0,
          shouldPrice: 0,
          siteCose: 0,
        },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 8 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 14 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        enterTime:{rules: [{ required: true, message: '请输入进店时间!' }]},
        month:{rules: [{ required: true, message: '请输入月份时间!' }]},
        },
        url: {
          add: "/crm/salesDetail/add",
          edit: "/crm/salesDetail/edit",
        },
      }
    },
    computed: {
      // getGrossProfit: function() {
      //   return this.model.grossProfit;
      // },
      // getGrossRate: function() {
      //   return this.model.grossRate;
      // },
      // getSalesCommissionPrice: function() {
      //   return this.model.salesCommissionPrice;
      // },
      // getProportionProfits: function() {
      //   return this.model.proportionProfits;
      // },
      // getRestPrice: function() {
      //   return this.model.restPrice;
      // },
      getRealPrice:function(){return this.model.realPrice;},
      getShouldPrice:function(){return this.model.shouldPrice;},
      getBuildingCost:function(){return this.model.buildingCost;},
      getBuildingTotil:function(){return this.model.buildingTotil;},
      getCommission:function(){return this.model.commission;},
      getForeignCose:function(){return this.model.foreignCose;},
      getFreight:function(){return this.model.freight;},
      getGrossProfit:function(){return this.model.grossProfit;},
      getMaintainCose:function(){return this.model.maintainCose;},
      getMaterialCost:function(){return this.model.materialCost;},
      getProceduresPrice:function(){return this.model.proceduresPrice;},
      getSalesBuildPrice:function(){return this.model.salesBuildPrice;},
      getSalesCommission:function(){return this.model.salesCommission;},
      getSalesCommissionPrice:function(){return this.model.salesCommissionPrice;},
      getSalesCost:function(){return this.model.salesCost;}, 
      getSiteCose:function(){return this.model.siteCose;}, 
      
    },
    watch: {
      /* getGrossProfit: {
        handler: function() {
          this.culGrossProfit();
        }
      },
      getGrossRate: {
        handler: function() {
          this.culGrossRate();
        }
      },
      getSalesCommissionPrice: {
        handler: function() {
          this.culSalesCommissionPrice();
        }
      },
      getProportionProfits: {
        handler: function() {
          this.culProportionProfits();
        }
      }, */
      // getRestPrice:{
      //   handler: function() {
      //     this.culRestPrice();
      //   }
      // },
      getRealPrice:{
        handler:function(){
          this.culRestPrice();
          this.culGrossProfit();this.culGrossRate();this.culSalesCommissionPrice();this.culProportionProfits();
        },
      },
      getShouldPrice:{
        handler:function(){
          this.culRestPrice();this.culGrossProfit();this.culGrossRate();this.culSalesCommissionPrice();this.culProportionProfits();
        },
      },
      getBuildingCost:{handler:function(){this.culGrossProfit();this.culGrossRate();this.culSalesCommissionPrice();this.culProportionProfits();}},
      getBuildingTotil:{handler:function(){this.culGrossProfit();this.culGrossRate();this.culSalesCommissionPrice();this.culProportionProfits();}},
      getCommission:{handler:function(){this.culGrossProfit();this.culGrossRate();this.culSalesCommissionPrice();this.culProportionProfits();}},
      getForeignCose:{handler:function(){this.culGrossProfit();this.culGrossRate();this.culSalesCommissionPrice();this.culProportionProfits();}},
      getFreight:{handler:function(){this.culGrossProfit();this.culGrossRate();this.culSalesCommissionPrice();this.culProportionProfits();}},
      getGrossProfit:{handler:function(){this.culGrossProfit();this.culGrossRate();this.culSalesCommissionPrice();this.culProportionProfits();}},
      getMaintainCose:{handler:function(){this.culGrossProfit();this.culGrossRate();this.culSalesCommissionPrice();this.culProportionProfits();}},
      getMaterialCost:{handler:function(){this.culGrossProfit();this.culGrossRate();this.culSalesCommissionPrice();this.culProportionProfits();}},
      getProceduresPrice:{handler:function(){this.culGrossProfit();this.culGrossRate();this.culSalesCommissionPrice();this.culProportionProfits();}},
      getSalesBuildPrice:{handler:function(){this.culGrossProfit();this.culGrossRate();this.culSalesCommissionPrice();this.culProportionProfits();}},
      getSalesCommission:{handler:function(){this.culGrossProfit();this.culGrossRate();this.culSalesCommissionPrice();this.culProportionProfits();}},
      getSalesCommissionPrice:{handler:function(){this.culGrossProfit();this.culGrossRate();this.culSalesCommissionPrice();this.culProportionProfits();}},
      getSalesCost:{handler:function(){this.culGrossProfit();this.culGrossRate();this.culSalesCommissionPrice();this.culProportionProfits();}},
      getSiteCose:{handler:function(){this.culGrossProfit();this.culGrossRate();this.culSalesCommissionPrice();this.culProportionProfits();}},
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        if(this.model==undefined){
          this.model={};
        }
        if(record.buildList!=undefined){
          this.detailList=record.buildList;
        }else{
           this.detailList=[];
        }
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'month','busNo','shop','name','phone','type','carNumber','carShelf','mileage','color','feedback','feedbackImg','oneCategory','twoCategory','proRemark','num','salesman','source','payType','foreignGroup','bill','oneCheck','twoCheck','threeCheck','createUser','updateUser'))
        //时间格式化
          this.form.setFieldsValue({month:this.model.month?moment(this.model.month):null})
          this.form.setFieldsValue({enterTime:this.model.enterTime?moment(this.model.enterTime):null})
          this.form.setFieldsValue({finishTime:this.model.finishTime?moment(this.model.finishTime):null})
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            this.calculateTotalAmount();
            this.model.buildList=this.detailList;
            let formData = Object.assign(this.model, values);
            //时间格式化
            formData.enterTime = formData.enterTime?formData.enterTime.format('YYYY-MM-DD HH:mm:ss'):null;
            formData.finishTime = formData.finishTime?formData.finishTime.format('YYYY-MM-DD HH:mm:ss'):null;
            
            console.log(formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },
      /*毛利润*/
      culGrossProfit(){
        //T6-Y6-Z6-AB6-AC6-AE6-AF6-AG6-AH6-AK6=实收小计-手续费-材料成本-运费-外出施工费用-维修费用/其他外协费-销售返佣-业务员提成-外援施工费用-施工提成总计
        let value=(this.model.realPrice||0)-(this.model.proceduresPrice||0)-(this.model.materialCost||0)-(this.model.freight||0)-
          (this.model.buildingCost||0)-(this.model.maintainCose||0)-(this.model.salesCommission||0)-
          (this.model.commission||0)-(this.model.foreignCose||0)-(this.model.buildingTotil||0);
        this.model.grossProfit = value;
      },
      /*毛利率*/
      culGrossRate(){
        //AS6/R6=毛利润/实收核算 /应收小计
        let value=0;
        if(this.model.shouldPrice==undefined){
          value=0;
        }else{
          value=(this.model.grossProfit||0)/this.model.shouldPrice*100;
        }
        this.model.grossRate = value.toFixed(2)+"%";
      },
      /*销售提成应收核算*/
      culSalesCommissionPrice(){
        let value=(this.model.shouldPrice||0)-(this.model.proceduresPrice||0)-(this.model.salesCost||0)-(this.model.freight||0)-
          (this.model.buildingCost||0)-(this.model.siteCose||0)-(this.model.maintainCose||0)-(this.model.salesCommission||0)-
          (this.model.commission||0)-(this.model.foreignCose||0)-(this.model.salesBuildPrice||0);
        this.model.salesCommissionPrice = value;
      },
      /*销售提成利润占比*/
      culProportionProfits(){
        //AS6/R6=毛利润/实收核算 /应收小计
        let value=0;
        if(this.model.shouldPrice==undefined){
          value=0;
        }else{
          value=((this.model.salesCommissionPrice||0))/this.model.shouldPrice*100;
        }
        this.model.proportionProfits = value.toFixed(2)+"%";
      },
      /*未收*/
      culRestPrice(){
        let value=0;
        value=(this.model.shouldPrice||0)-(this.model.realPrice||0);
        this.model.restPrice=value;
      },
      deleteItem(item,index){
        this.detailList.splice(index,1);
        if(this.detailList.length<=0){
          this.addItem();
        }
        this.calculateTotalAmount();
      },
      addItem(){
        this.detailList.push({
            name:"",
            price:"",
          });
      },
      itemPriceChanged(val){
        if(isNaN(val)){
          val=0;
        }
        var pattern = /^\d+.?\d{0,2}$/;
        if(!pattern.test(val))
          val =parseFloat(val).toFixed(2);
       this.calculateTotalAmount();
      },
      calculateTotalAmount(){
        var totalPrice=0;
        this.detailList =this.detailList.map((item)=>{
            if(item.price && !isNaN(item.price)){
              totalPrice+=parseFloat(item.price);
            }
            return item;
        });
        this.model.buildingTotil=parseInt(totalPrice);
        // this.form.setFieldsValue(pick(this.model,'totalPrice'))
        this.culGrossProfit();this.culGrossRate();this.culSalesCommissionPrice();this.culProportionProfits();
      },
    }
  }
</script>

<style lang="less" scoped>

</style>